/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package classcreator.DB;

import classcreator.ClassCreator;
import com.mysql.jdbc.Connection;
import com.mysql.jdbc.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Samus
 */
public class DBTables {

    private static DBTables instance = new DBTables();

    public static DBTables getInstance() {
        return instance;
    }

    public void createDatabase() throws SQLException {
        try {
            Connection conn = (Connection) DataBaseConnFactory.getInstance().obtenerConnexion();
            String query = "create schema IF NOT EXISTS " + ClassCreator.getInstance().getPackagename();
            PreparedStatement ps = (PreparedStatement) conn.prepareStatement(query);
            ps.execute();
        } catch (Exception ex) {
            Logger.getLogger(DBTables.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    public void executeQuery(String query) throws SQLException {
        try {
            java.sql.Connection conn = DataBaseConnFactory.getInstance().obtenerNewConexion();
            PreparedStatement ps = (PreparedStatement) conn.prepareStatement(query);
            ps.execute();
            ps.close();
        } catch (Exception ex) {
            Logger.getLogger(DBTables.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
